package test.course.pages {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class Button extends Sprite {

		private var _textField:TextField;

		public function Button() {
			graphics.lineStyle(1,0x000000)
			graphics.beginFill(0x8080ff);
			graphics.drawRect(0,0,200,20);
			graphics.endFill();

			_textField=new TextField();
			_textField.textColor=0xffffff;
			_textField.x=5;
			_textField.y=5;
			_textField.text="button";
			_textField.width=180;
			_textField.height=15;
			addChild(_textField);

			mouseChildren=false;
			buttonMode=true;

			addEventListener(MouseEvent.CLICK,onClick);
		}
		
		/**
		 * Clicked.
		 */
		protected function onClick(event:MouseEvent):void
		{
			dispatchEvent(new Event("clicked"));
		}
		
		[Property]
		public function set label(value:String):void {
			_textField.text=value;
		}

		[Property]
		override public function set x(value:Number):void {
			super.x=value;
		}

		[Property]
		override public function set y(value:Number):void {
			super.y=value;
		}
	}
}